package com.study.sms.entity.vo;

import java.io.Serializable;

/**
 * @author mjy
 * @date 2021/12/9 11:23
 */
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    
    private int code;
    
    private String msg;

    private T data;

    public static <T> Result<T> success() {
        return restResult(null, BaseRespCode.SUCCESS_CODE,  BaseRespCode.SUCCESS_MSG);
    }


    public static <T> Result<T> success(T data) {
        return restResult(data, BaseRespCode.SUCCESS_CODE, BaseRespCode.SUCCESS_MSG);
    }

    public static <T> Result<T> success(T data, String msg) {
        return restResult(data, BaseRespCode.SUCCESS_CODE, msg);
    }

    public static <T> Result<T> error() {
        return restResult(null,BaseRespCode.ERROR_CODE, BaseRespCode.ERROR_MSG);
    }

    public static <T> Result<T> error(String msg) {
        return restResult(null, BaseRespCode.ERROR_CODE, msg);
    }

    public static <T> Result<T> error(T data) {
        return restResult(data, BaseRespCode.ERROR_CODE, null);
    }

    public static <T> Result<T> error(T data, String msg) {
        return restResult(data, BaseRespCode.ERROR_CODE, msg);
    }

    private static <T> Result<T> restResult(T data, int code, String msg) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setData(data);
        result.setMsg(msg);
        return result;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
